package com.spark.exception;

import com.spark.exception.enums.IResponseEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class UnifiedMessageSource {
    public String getMessage(IResponseEnum responseEnum, Object... args) {
        log.error(responseEnum.getCode() + ":" + responseEnum.getMessage(), args);
        int code = responseEnum.getCode();
        if (code >= 400 && code < 500) {
            return "请求错误";
        } else if (code >= 500 && code < 600) {
            return "服务器错误";
        }
        return responseEnum.getMessage();
    }
}
